<?php

class Video_Model extends CI_Model {

    function getAllVideo($per_page, $offset) {
        $this->db->select('ID, VIDEO_NAME, VIDEO_DETAIL, VIDEO_PATH');
        $this->db->from('VIDEO');
        $this->db->limit($per_page, $offset);
        $query = $this->db->get();

        return $query;
    }

    function searchVideo($course, $name, $per_page, $offset) {

        $this->db->from('VIDEO');

        $this->db->join('COURSE', 'COURSE.ID = VIDEO.COURSE_ID');
        $this->db->where('VIDEO.COURSE_ID', $course);

        if ($name) {
            $this->db->like('VIDEO_NAME', $name);
        }
        
        $this->db->limit($per_page, $offset);

        $query = $this->db->get();

        return $query;
    }

    function insertVideo($video) {
        if($this->db->insert('VIDEO', $video)){
            return true;
        }else{
            return false;
        }
    }

    function getAllVideoByCourse($per_page, $offset, $courseIDList) {
        $this->db->select('*');
        $this->db->from('VIDEO');
        $this->db->join('COURSE', 'COURSE.ID = VIDEO.COURSE_ID');
        $this->db->where_in('VIDEO.COURSE_ID', $courseIDList);
        $this->db->limit($per_page, $offset);
        $this->db->order_by('COURSE.ID', 'asc');

        $query = $this->db->get();
        return $query;
    }

    function getVideoByID($videoID) {
        $this->db->from('VIDEO');
        $this->db->where('ID', $videoID);
        $query = $this->db->get();

        return $query;
    }

}

?>
